package gupao.concurrency.kms;

import lombok.extern.slf4j.Slf4j;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

@Slf4j
public class RequestListMock {

    public static List<RequestModel> mockRequests() {
        try {
            List<RequestModel> list = new ArrayList<>();
            List<String> idSignList = readIdSignList();
            for(int i = 0; i < 10; i++){
                for (String idSignStr : idSignList) {
                    if(idSignStr.startsWith("#")){
                        continue;
                    }
                    String[] idSign = idSignStr.split(",");
                    LinkedHashMap<String, String> map = new LinkedHashMap<>();
                    map.put("id", idSign[0]);
                    RequestModel model = new RequestModel(map, idSign[1]);
                    list.add(model);
                }
            }
            return list;
        } catch (Exception e) {
            log.error("", e);
            return null;
        }
    }

    private static List<String> readIdSignList() throws Exception {
        List<String> idSignList = new ArrayList<>();
        try (FileInputStream inputStream = new FileInputStream("mock_file.txt");
             BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream))) {
            String idSign = null;
            int idx = 1;
            while ((idSign = bufferedReader.readLine()) != null) {
                idSignList.add(idSign);
            }
        }
        return idSignList;
    }
}